﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Comm.Web.View
{
    public partial class UserOrder : Basepage
    {
        BLL.OrdersService bllorder = new BLL.OrdersService();
        protected string strHtml = string.Empty;
        protected string strMsg = string.Empty;
        public override void SonLoad()
        {
            //Model.Orders _orderBook = bllorder.GetModel(UserNow.uId);
            DataTable dt1 = bllorder.getUserOrders(UserNow.uId);
            DataTable dt2 = bllorder.getUserOrder(UserNow.uId);

            StringBuilder sb = new StringBuilder(2000);
            for (int i = 0; i < dt1.Rows.Count;i++ )
            {
                int count = 0;
                sb.Append("<tr><td colspan=\"2\"><span style=\"margin-left:30px;\">" + dt1.Rows[i]["OrderDate"] + "  订单号：" + dt1.Rows[i]["OrderId"] + "</span><span style=\"margin-left:100px;\"> 实付款：" + dt1.Rows[i]["TotalPrice"] + "元</span></td></tr>");
                for (int j = 0; j < dt2.Rows.Count; j++) 
                {
                    if (dt1.Rows[i]["OrderId"].ToString() == dt2.Rows[j]["OrderId"].ToString()) 
                    {
                        if (count == 0)
                        {
                            sb.Append("<tr><td colspan=\"5\"><table id=\"tbList\"><tr><th>图书照片</th><th>图书名称</th><th>单价(元)</th><th>购买数量</th><th>订单状态</th>");
                            count++;
                        }
                        if (int.Parse(dt2.Rows[j]["state"].ToString()) == 0)
                        {
                             strMsg = "未处理";
                        }
                        else if(int.Parse(dt2.Rows[j]["state"].ToString()) == 1)
                        {
                             strMsg = "已处理";
                        }
                        sb.Append("<tr class=\"align_Center\">");
                        sb.Append("<td style=\"width:20%; \"><a id=\"" + dt2.Rows[j]["BookID"] + "\" strId=\"strId\"><img style=\"cursor: pointer; width:95px; height:121px;border=0\" alt=\"" + dt2.Rows[j]["Title"] + "\"  src=\"../Images/BookCovers/" + dt2.Rows[j]["ISBN"] + ".jpg\"></td>");
                        sb.Append(" <td class=align_Left><a onmouseover=\"\" style=\"cursor:pointer;\" onmouseout=\"\" onclick=\"\" id=\"btn_"+dt2.Rows[j]["BookID"]+"\" EditId=\"EditId\" target=\"_blank\" >" + dt2.Rows[j]["Title"] + "</a></td>");
                        sb.Append("<td style=\"width:10%; \"><span class=\"price\">￥" + dt2.Rows[j]["UnitPrice"] + "</span></td>");
                        sb.Append("<td style=\"width:10%; \"><span class=\"price\">" + dt2.Rows[j]["Quantity"] + "</span></td>");
                        sb.Append("<td style=\"width:8%; \">" + strMsg + "</td>");
                    }          
                }
                sb.Append("</tr></table></td></tr>");
            }
            strHtml = sb.ToString();

        }
    }
}